package com.bjpowerrnode.javase.date;

import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;

public class LocalTimeWith {
    public static void main(String[] args) {
        long month_of_year = 5;

        // Instantiates two LocalDate
        LocalDate l_da1 = LocalDate.parse("2007-04-04");
        LocalDate l_da2 = LocalDate.of(2008, Month.FEBRUARY, 06);

        // Display l_da1,l_da2
        System.out.println("LocalDate l_da1,l_da2 : ");
        System.out.println("l_da1: " + l_da1);
        System.out.println("l_da2: " + l_da2);
        System.out.println("month_of_year to update: " + month_of_year);

        LocalDate l_date = l_da1.with(ChronoField.MONTH_OF_YEAR, month_of_year);

        // Display l_date
        System.out.print("l_da1.with(ChronoField.MONTH_OF_YEAR,month_of_year): ");
        System.out.println(l_date);

        // Here, with(TemporalAdjusters)
        // returns an adjusted instance
        // of this date l_da2
        l_date = l_da2.with(Month.JUNE).with(TemporalAdjusters.firstDayOfMonth());

        System.out.print("l_da2.with(Month.JUNE).with(TemporalAdjusters.firstDayOfMonth()): ");
        System.out.println(l_date);

        LocalDate now = LocalDate.now();
        System.out.println("now="+now);
        LocalDate end = now.with(TemporalAdjusters.firstDayOfNextYear());
        System.out.println("end="+end);
        LocalDate start = now.with(TemporalAdjusters.lastDayOfYear());
        System.out.println("start="+start);
        LocalDate startMinus = start.minusYears(1);
        System.out.println("startMinus="+startMinus);
    }
}
